import { Component } from '@angular/core';
import { IonicPage, Refresher, ModalController } from 'ionic-angular';

// service
import { HideBarsService } from '../../../providers/utils/hideBars.service';
import { OrdersService } from '../../../providers/service/orders.service';
import { Observable } from "rxjs/Observable";
// 常量
import * as PageConstant from '../../../constant/pageConstant';

/**
 * 借款记录
 */
@IonicPage()
@Component({
  selector:'page-borrow-order',
  templateUrl: 'borrow-order.html'
})
export class BorrowOrderPage
{

  private orderList$: Observable<any>; // 订单列表
  constructor(
    public modalCtrl: ModalController,
    private ordersService: OrdersService,
    private hideBars: HideBarsService,
  )
  {
    this.ordersService.getUserOrderList(null);
  }

  /*** 初始化数据
   * */
  initData()
  {
    this.orderList$= this.ordersService.getOrders()
      .filter(orders=> !!orders.orderList)
      .map(orders=> orders.orderList);
  }

  /*** 页面进入
   * */
  ionViewWillEnter()
  {
    this.initData();
    this.hideBars.changeTabBarsElementBottom('-5rem');
  }

  /*** 页面离开
   * */
  ionViewWillLeave()
  {
    this.hideBars.changeTabBarsElementBottom('0');
  }

  /*** 上拉刷新
   * */
  executeRefresh(refresher: Refresher) {
    this.ordersService.getUserOrderList(refresher);
  }


  /** 去订单详情
   * */
  doOrderDetails(item): void
  {
    debugger;
    const modal = this.modalCtrl.create(PageConstant.OrderDetailsPage, {
      data: item
    },{
      showBackdrop: false,
      enableBackdropDismiss: false,
    });
    // modal.onDidDismiss(data => {
    //   debugger;
    // });
    modal.present();
  }

}
